// Split a number into single digits.
// This example shows how to split a number into single digits eg 1024 would print 1 0 2 4
// We also make use of the stack object to print out the digits in the correct order.
// By Ben 24/10/2018

#include <iostream>
#include <stack>
using namespace std;

using std::cout;
using std::endl;

int main()
{
	stack<int>digits;
	int num = 655356;

	int tmp = num;
	int digit = 0;

	while (tmp > 0){
		//Get single digit
		digit = tmp % 10;
		//Keep dividing the number by 10
		tmp /= 10;
		//Push number on stack.
		digits.push(digit);
	}
	
	//Output each digit with a space
	while (!digits.empty()){
		//Output the digit
		std::cout << digits.top() << " ";
		//Pop of the next item
		digits.pop();
	}

	std::cout << endl;

	system("pause");
	return 0;
}
